﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;

namespace SharePoint.Accelerators.CentralAdmin.CommandSearch.CommandSearchSuggest
{
    /// <summary>
    /// Source: SPDevWiki: http://tinyurl.com/ygrzvbc
    /// </summary>
    public static class Extensions
    {
        public static bool ListExists(this SPWeb web, string listName)
        {
            return web.Lists.Cast<SPList>().Any(list => string.Compare(list.Title, listName, true) == 0);
        }
    }


    [ToolboxItemAttribute(false)]
    public class CommandSearchSuggest : System.Web.UI.WebControls.WebParts.WebPart
    {
        public CommandSearchSuggest()
        {
        }

        private const string _centralAdminLinks = @"var results = [
                                                	{ value: 'Applications', label: 'Applications', desc: '/applications.aspx', icon: '' },
                                                    { value: 'Manage web applications', label: 'Manage web applications', desc: '/_admin/WebApplicationList.aspx ', icon: '' },
                                                    { value: 'Create site collections', label: 'Create site collections', desc: '/_admin/createsite.aspx', icon: '' },
                                                    { value: 'Manage service applications', label: 'Manage service applications', desc: '/_admin/ServiceApplications.aspx', icon: '' },
                                                    { value: 'Manage content databases', label: 'Manage content databases', desc: '/_admin/CNTDBADM.aspx', icon: '' },
                                                    { value: 'Monitoring', label: 'Monitoring', desc: '/monitoring.aspx', icon: '' },
                                                    { value: 'Review problems and solutions', label: 'Review problems and solutions', desc: '/Lists/HealthReports', icon: '' },
                                                    { value: 'Check job status', label: 'Check job status', desc: '/_admin/Timer.aspx', icon: '' },
                                                    { value: 'View Web Analytics reports', label: 'View Web Analytics reports', desc: '/_layouts/WebAnalytics/WebAppSelection.aspx?t=WebApplicationSelectionReport&l=wa', icon: '' },
                                                    { value: 'Security', label: 'Security', desc: '/security.aspx', icon: '' },
                                                    { value: 'Manage the farm administrators group', label: 'Manage the farm administrators group', desc: '/_layouts/people.aspx?MembershipGroupId=3', icon: '' },
                                                    { value: 'Configure service accounts', label: 'Configure service accounts', desc: '/_admin/FarmCredentialManagement.aspx', icon: '' },
                                                    { value: 'General Application Settings', label: 'General Application Settings', desc: '/generalapplicationsettings.aspx', icon: '' },
                                                    { value: 'Configure send to connections', label: 'Configure send to connections', desc: '/_admin/OfficialFileAdmin.aspx', icon: '' },
                                                    { value: 'Configure content deployment paths and jobs', label: 'Configure content deployment paths and jobs', desc: '/_admin/Deployment.aspx', icon: '' },
                                                    { value: 'Manage form templates', label: 'Manage form templates', desc: '/_admin/ManageFormTemplates.aspx', icon: '' },
                                                    { value: 'System Settings', label: 'System Settings', desc: '/systemsettings.aspx', icon: '' },
                                                    { value: 'Manage servers in this farm', label: 'Manage servers in this farm', desc: '/_admin/FarmServers.aspx', icon: '' },
                                                    { value: 'Manage services on server', label: 'Manage services on server', desc: '/_admin/Server.aspx', icon: '' },
                                                    { value: 'Manage farm features', label: 'Manage farm features', desc: '/_admin/ManageFarmFeatures.aspx', icon: '' },
                                                    { value: 'Configure alternate access mappings', label: 'Configure alternate access mappings', desc: '/_admin/AlternateUrlCollections.aspx', icon: '' },
                                                    { value: 'Backup and Restore', label: 'Backup and Restore', desc: '/backups.aspx', icon: '' },
                                                    { value: 'Perform a backup', label: 'Perform a backup', desc: '/_admin/Backup.aspx', icon: '' },
                                                    { value: 'Restore from a backup', label: 'Restore from a backup', desc: '/_admin/BackupHistory.aspx?restore=1&filter=1', icon: '' },
                                                    { value: 'Perform a site collection backup', label: 'Perform a site collection backup', desc: '/_admin/SiteCollectionBackup.aspx', icon: '' },
                                                    { value: 'Upgrade and Migration', label: 'Upgrade and Migration', desc: '/upgradeandmigration.aspx', icon: '' },
                                                    { value: 'Convert farm license type', label: 'Convert farm license type', desc: '/_admin/Conversion.aspx', icon: '' },
                                                    { value: 'Check product and patch installation status', label: 'Check product and patch installation status', desc: '/_admin/PatchStatus.aspx', icon: '' },
                                                    { value: 'Check upgrade status', label: 'Check upgrade status', desc: '/_admin/UpgradeStatus.aspx', icon: '' },
                                                    { value: 'Configuration Wizards', label: 'Configuration Wizards', desc: '/configurationwizards.aspx', icon: '' },
                                                    { value: 'Manage web applications', label: 'Manage web applications', desc: '/_admin/WebApplicationList.aspx', icon: '' },
                                                    { value: 'Delete a site collection', label: 'Delete a site collection', desc: '/_admin/delsite.aspx?SiteId=', icon: '' },
                                                    { value: 'Confirm site use and deletion', label: 'Confirm site use and deletion', desc: '/_admin/DeleteSiteConfig.aspx', icon: '' },
                                                    { value: 'Specify quota templates', label: 'Specify quota templates', desc: '/_admin/ManageQuotaTemplate.aspx', icon: '' },
                                                    { value: 'Configure quotas and locks', label: 'Configure quotas and locks', desc: '/_admin/sitequota.aspx', icon: '' },
                                                    { value: 'Change site collection administrators', label: 'Change site collection administrators', desc: '/_admin/owners.aspx', icon: '' },
                                                    { value: 'View all site collections', label: 'View all site collections', desc: '/_admin/SiteCollections.aspx?ReturnSelectionPage=/applications.aspx', icon: '' },
                                                    { value: 'Configure self-service site creation', label: 'Configure self-service site creation', desc: '/_admin/ConfigSSC.aspx  ', icon: '' },
                                                    { value: 'Configure service application associations', label: 'Configure service application associations', desc: '/_admin/ApplicationAssociations.aspx', icon: '' },
                                                    { value: 'Specify the default database server', label: 'Specify the default database server', desc: '/_admin/defaultcontentdb.aspx', icon: '' },
                                                    { value: 'Configure the data retrieval service', label: 'Configure the data retrieval service', desc: '/_admin/DspSettings.aspx', icon: '' },
                                                    { value: 'Configure outgoing e-mail settings', label: 'Configure outgoing e-mail settings', desc: '/_admin/globalemailconfig.aspx', icon: '' },
                                                    { value: 'Configure incoming e-mail settings', label: 'Configure incoming e-mail settings', desc: '/_admin/IncomingEmail.aspx', icon: '' },
                                                    { value: 'Configure mobile account', label: 'Configure mobile account', desc: '/_admin/globalxmsconfig.aspx', icon: '' },
                                                    { value: 'Manage farm solutions', label: 'Manage farm solutions', desc: '/_admin/Solutions.aspx', icon: '' },
                                                    { value: 'Manage user solutions', label: 'Manage user solutions', desc: '/_admin/UserSolutions.aspx', icon: '' },
                                                    { value: 'Configure privacy options', label: 'Configure privacy options', desc: '/_admin/Privacy.aspx', icon: '' },
                                                    { value: 'Configure cross-firewall access zone', label: 'Configure cross-firewall access zone', desc: '/_admin/SelectCrossFirewallAccessZone.aspx', icon: '' },
                                                    { value: 'Review rule definitions', label: 'Review rule definitions', desc: '/Lists/HealthRules', icon: '' },
                                                    { value: 'Review job definitions', label: 'Review job definitions', desc: '/_admin/ServiceJobDefinitions.aspx', icon: '' },
                                                    { value: 'View administrative reports', label: 'View administrative reports', desc: '/AdminReports', icon: '' },
                                                    { value: 'Configure diagnostic logging', label: 'Configure diagnostic logging', desc: '/_admin/metrics.aspx', icon: '' },
                                                    { value: 'Review Information Management Policy Usage Reports', label: 'Review Information Management Policy Usage Reports', desc: '/_admin/PolicyRptConfig.aspx', icon: '' },
                                                    { value: 'View health reports', label: 'View health reports', desc: '/_admin/HealthReport.aspx', icon: '' },
                                                    { value: 'Configure usage and health data collection', label: 'Configure usage and health data collection', desc: '/_admin/LogUsage.aspx', icon: '' },
                                                    { value: 'Configure backup settings', label: 'Configure backup settings', desc: '/_admin/BackupSettings.aspx', icon: '' },
                                                    { value: 'View backup and restore history', label: 'View backup and restore history', desc: '/_admin/BackupHistory.aspx', icon: '' },
                                                    { value: 'Check backup and restore job status', label: 'Check backup and restore job status', desc: '/_admin/BackupStatus.aspx  ', icon: '' },
                                                    { value: 'Export a site or list', label: 'Export a site or list', desc: '/_admin/SiteAndListExport.aspx', icon: '' },
                                                    { value: 'Recover data from an unattached content database', label: 'Recover data from an unattached content database', desc: '/_admin/UnattachedDbSelect.aspx', icon: '' },
                                                    { value: 'Check granular backup job status', label: 'Check granular backup job status', desc: '/_admin/SiteBackupOrExportStatus.aspx', icon: '' },
                                                    { value: 'Approve or reject distribution groups', label: 'Approve or reject distribution groups', desc: '/Lists/Distribution%20Groups/AllItems.aspx', icon: '' },
                                                    { value: 'Specify web application user policy', label: 'Specify web application user policy', desc: '/_admin/policy.aspx', icon: '' },
                                                    { value: 'Configure managed accounts', label: 'Configure managed accounts', desc: '/_admin/ManagedAccounts.aspx', icon: '' },
                                                    { value: 'Configure password change settings', label: 'Configure password change settings', desc: '/_admin/PasswordSettings.aspx', icon: '' },
                                                    { value: 'Specify authentication providers', label: 'Specify authentication providers', desc: '/_admin/authenticationproviders.aspx', icon: '' },
                                                    { value: 'Manage trust', label: 'Manage trust', desc: '/_admin/ManageTrust.aspx', icon: '' },
                                                    { value: 'Manage antivirus settings', label: 'Manage antivirus settings', desc: '/_admin/AVAdmin.aspx', icon: '' },
                                                    { value: 'Define blocked file types', label: 'Define blocked file types', desc: '/_admin/BlockedFileType.aspx', icon: '' },
                                                    { value: 'Manage web part security', label: 'Manage web part security', desc: '/_admin/SPSecuritySettings.aspx', icon: '' },
                                                    { value: 'Configure self-service site creation', label: 'Configure self-service site creation', desc: '/_admin/ConfigSSC.aspx', icon: '' },
                                                    { value: 'Configure information rights management', label: 'Configure information rights management', desc: '/_admin/IrmAdmin.aspx', icon: '' },
                                                    { value: 'Configure Information Management Policy', label: 'Configure Information Management Policy', desc: '/_admin/Policyfeatures.aspx ', icon: '' },
                                                    { value: 'Enable Enterprise Features', label: 'Enable Enterprise Features', desc: '/_admin/SkuUpgrade.aspx', icon: '' },
                                                    { value: 'Enable Features on Existing Sites', label: 'Enable Features on Existing Sites', desc: '/_admin/enablefeatures.aspx', icon: '' },
                                                    { value: 'Review database status', label: 'Review database status', desc: '/_admin/DatabaseStatus.aspx', icon: '' },
                                                    { value: 'Farm-Wide Search Administration', label: 'Farm-Wide Search Administration', desc: '/searchfarmdashboard.aspx', icon: '' },
                                                    { value: 'Administration Reports', label: 'Administration Reports', desc: '/AdminReports/Forms/AllItems.aspx', icon: '' },
                                                    { value: 'Term Store Management Tool', label: 'Term Store Management Tool', desc: '/_Layouts/termstoremanager.aspx', icon: '' },
                                                    { value: 'Import PerformancePoint Server 2007 Content', label: 'Import PerformancePoint Server 2007 Content', desc: '/_admin/pps/Welcome.aspx?scenarioid=ppsupgrade', icon: ''},
                                                    {value: 'Configure usage and health data collection', label: 'Configure usage and health data collection', desc: '/_admin/LogUsage.aspx', icon: ''}
                                                    {0}];";

        private string _jQueryPath = "/JQuery/jquery-1.4.2.min.js";
        private string _jQueryUIPath = "/JQuery/jquery-ui-1.8rc3.custom.min.js";
        private string _searchSuggestPath = "/JQuery/CommandSearchSuggest.js";
        private string _cssFile = "/JQuery/CSS/ui-lightness/jquery-ui-1.8rc3.custom.css";
       

        [WebBrowsable(true)]
        [WebDisplayName("CSS File Path")]
        [WebDescription("Path to CSS File.")]
        [Personalizable(PersonalizationScope.Shared)]
        [Category("Resources")]
        public string CssFile
        {
            get { return _cssFile; }
            set { _cssFile = value; }
        }

        [WebBrowsable(true)]
        [WebDisplayName("Search Suggest Path")]
        [WebDescription("Path to Search Sugest Library.")]
        [Personalizable(PersonalizationScope.Shared)]
        [Category("Resources")]
        public string SearchSuggestPath
        {
            get { return _searchSuggestPath; }
            set { _searchSuggestPath = value; }
        }

        [WebBrowsable(true)]
        [WebDisplayName("JQuery UI Path")]
        [WebDescription("Path to JQuery UI Library.")]
        [Personalizable(PersonalizationScope.Shared)]
        [Category("Resources")]
        public string JQueryUIPath
        {
            get { return _jQueryUIPath; }
            set { _jQueryUIPath = value; }
        }

        [WebBrowsable(true)]
        [WebDisplayName("JQuery Path")]
        [WebDescription("Path to JQuery Library.")]
        [Personalizable(PersonalizationScope.Shared)]
        [Category("Resources")]
        public string JQueryPath
        {
            get { return _jQueryPath; }
            set { _jQueryPath = value; }
        }

        private bool IsSandbox()
        {
            if (AppDomain.CurrentDomain.FriendlyName == "User Code Execution Partially Trusted Asp.net AppDomain" ||
                AppDomain.CurrentDomain.FriendlyName == "Sandboxed Code Execution Partially Trusted Asp.net AppDomain")
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        protected override void CreateChildControls()
        {
            HtmlGenericControl jQueryLink = new HtmlGenericControl("script");
            jQueryLink.Attributes.Add("type", "text/javascript");
            jQueryLink.Attributes.Add("src", JQueryPath);
            Controls.Add(jQueryLink);

            HtmlGenericControl jQueryUILink = new HtmlGenericControl("script");
            jQueryUILink.Attributes.Add("type", "text/javascript");
            jQueryUILink.Attributes.Add("src", JQueryUIPath);
            Controls.Add(jQueryUILink);

            HtmlGenericControl csslink = new HtmlGenericControl("LINK");
            csslink.Attributes.Add("rel", "stylesheet");
            csslink.Attributes.Add("type", "text/css");
            csslink.Attributes.Add("href", CssFile);
            Controls.Add(csslink);

            LiteralControl literal = new LiteralControl();
            literal.Text = "<div class=\"demo\"<div class=\"ui-widget\"><label for=\"tags\">Search for: </label><input title=\"Search...\" style=\"width:300px\" id=\"tags\"></div></div>";
            Controls.Add(literal);

            StringBuilder serviceApplicationsLinks = new StringBuilder();
#if !Sandboxed
            if (!IsSandbox())
            {
                serviceApplicationsLinks = GenerateServiceApplicationsLinks();
            }
#endif


            HtmlGenericControl centralAdminLinks = new HtmlGenericControl("script");
            centralAdminLinks.Attributes.Add("type", "text/javascript");
            centralAdminLinks.InnerText = _centralAdminLinks.Replace("{0}", serviceApplicationsLinks.ToString());
            Controls.Add(centralAdminLinks);

            HtmlGenericControl searchSuggestLink = new HtmlGenericControl("script");
            searchSuggestLink.Attributes.Add("type", "text/javascript");
            searchSuggestLink.Attributes.Add("src", SearchSuggestPath);
            Controls.Add(searchSuggestLink);

            base.CreateChildControls();
        }

        private string GenerateLink(string Title, string Link, string ServiceApplication, string Id)
        {
            return string.Format(", {{ value: '{0} ({1})', label: '{0} ({1})', desc: '{2}{3}', icon: '' }}\n", Title, ServiceApplication, Link, Id);
        }

#if !Sandboxed
        private StringBuilder GenerateServiceApplicationsLinks()
        {
            StringBuilder links = new StringBuilder();

            foreach (Microsoft.SharePoint.Administration.SPService service in Microsoft.SharePoint.Administration.SPFarm.Local.Services)
            {
                if (service.Applications.Count > 0)
                {
                    foreach (Microsoft.SharePoint.Administration.SPServiceApplication application in service.Applications)
                    {
                        switch (application.TypeName)
                        {
                            case "Access Services Web Service Application":
                                links.Append(GenerateLink("Manage Access Services", "/_admin/AccessServerSettingsPage.aspx?Id=", application.Name, application.Id.ToString()) + "\n");
                                break;
                            case "Business Data Connectivity Service Application":
                                links.Append(GenerateLink("View External Content Types", "/_admin/BDC/ViewBDCApplication.aspx?AppId=", application.Name, application.Id.ToString()) + "\n");
                                break;
                            case "Excel Services Web Service Application":
                                links.Append(GenerateLink("Manage Excel Services", "/_admin/ExcelServicesAdmin.aspx?Id=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Excel Services Settings", "/_admin/ExcelServerSettings.aspx?Id=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Excel Services Trusted File Locations", "/_admin/ExcelServerTrustedLocations.aspx?Id=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Excel Services Trusted Data Providers", "/_admin/ExcelServerSafeDataProviders.aspx?Id=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Excel Services Trusted Data Connection Libraries", "/_admin/ExcelServerTrustedDcls.aspx?Id=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Excel Services User-Defined Functions", "/_admin/ExcelServerUserDefinedFunctions.aspx?Id=", application.Name, application.Id.ToString()));
                                break;
                            case "Search Service Application":
                                // FAST Admin?
                                links.Append(GenerateLink("Search Administration", "/searchadministration.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Manage Content Sources", "/_admin/search/listcontentsources.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Manage Crawl Rules", "/_admin/search/managecrawlrules.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Crawl Log - Content Source", "/_admin/search/LogContentSources.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Crawl Log - Host Name", "/_admin/search/logsummary.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Crawl Log - URL", "/_admin/search/logviewer.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Crawl Log - Crawl History", "/_admin/search/logcrawlhistory.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Crawl Log - Error Message", "/_admin/search/logerrorhistory.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Server Name Mappings", "/_admin/search/listservernamemappings.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Host Distribution Rules", "/_admin/search/managehostdistrules.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("File Types", "/_admin/search/managefiletypes.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Reset Crawled Content ", "/_admin/search/searchreset.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Crawler Impact Rules", "/_admin/search/managesitehitrules.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Specify Authoritative Pages", "/_admin/search/editrelevancesettings.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Manage Federated Locations", "/_admin/search/managefederatedlocations.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Metadata Property Mappings", "/_admin/search/listmanagedproperties.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("View Scopes", "/_admin/search/viewscopes.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Search Result Removal", "/_admin/search/searchresultremoval.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Web Analytics Reports - Summary", "/_layouts/WebAnalytics/Report.aspx?t=SummaryReport&l=sa&appid=", application.Name, application.Id.ToString()));
                                break;
                            case "PerformancePoint Service Application":
                                links.Append(GenerateLink("Manage PerformancePoint Services", "/_admin/ManagePpsBiService.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("PerformancePoint Service Application Settings", "/_admin/EditPpsBiServiceSettings.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Trusted Data Source Locations", "/_admin/ListPpsTrustedDataSourceLocations.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Trusted Content Locations", "/_admin/ListPpsTrustedContentLocations.aspx?appid=", application.Name, application.Id.ToString()));
                                break;
                            case "Secure Store Service Application":
                                links.Append(GenerateLink("Secure Store Service", "/_admin/sssvc/ManageSSSvcApplication.aspx?AppId=", application.Name, application.Id.ToString()));
                                break;
                            case "User Profile Service Application":
                                links.Append(GenerateLink("Manage Profile Service", "/_layouts/ManageUserProfileServiceApplication.aspx?ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Manage User Properties", "/_layouts/MgrProperty.aspx?ProfileType=User&ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Manage User Profiles", "/_layouts/ProfMngr.aspx?ConsoleView=Active&ProfileType=User&ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Manage User Sub-types", "/_layouts/ManageSubTypes.aspx?ProfileType=User&ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("View Audiences", "/_layouts/Audience_List.aspx?ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Specify Compilation Schedule", "/_layouts/Audience_Sched.aspx?ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Manage Policy", "/_layouts/ManagePrivacyPolicy.aspx?ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Synchronization Connections", "/_layouts/mgrdsserver.aspx?ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Configure Synchronization Settings", "/_layouts/synchronizationsetting.aspx?ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Start Profile Synchronization", "/_layouts/syncnow.aspx?ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Manage Organization Properties", "/_layouts/MgrProperty.aspx?ProfileType=Organization&ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Manage Organization Sub-types", "/_layouts/ManageSubTypes.aspx?ProfileType=Organization&ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("My Site Settings", "/_layouts/PersonalSites.aspx?ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Trusted My Site Host Locations", "/_layouts/ManageLinks.aspx?LinksType=0&ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Personalization site links", "/_layouts/ManageLinks.aspx?LinksType=1&ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Published links to Office client applications", "/_layouts/ManageLinks.aspx?LinksType=2&ApplicationID=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Manage Social Tags and Notes", "/_layouts/ManageSocialItems.aspx?ApplicationID", application.Name, application.Id.ToString()));
                                break;
                            case "Visio Graphics Service Application":
                                links.Append(GenerateLink("Manage the Visio Graphics Service", "/_admin/VisioServiceLanding.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Visio Graphics Service Settings", "/_admin/VisioEditServiceSettings.aspx?appid=", application.Name, application.Id.ToString()));
                                links.Append(GenerateLink("Visio Graphics Service Trusted Data Providers", "/_admin/VisioDataProviders.aspx?appid=", application.Name, application.Id.ToString()));
                                break;
                            case "Word Automation Services":
                                links.Append(GenerateLink("Manage Word Automation Services", "/_admin/WordServerManage.aspx?id=", application.Name, application.Id.ToString()));
                                break;
                            case "Word Viewing Service Application":
                                links.Append(GenerateLink("Manage Word Viewing Service", "/_admin/OvsConfig.aspx?id=", application.Name, application.Id.ToString()));
                                break;
                            default:
                                break;
                        }
                    }
                }

            }

            return links;
        }
#endif

        protected override void RenderContents(HtmlTextWriter writer)
        {
            base.RenderContents(writer);
        }
    
    }
}
